//
//  UIBarButtonItem+Extensions.swift
//  小贝微博
//
//  Created by 汪波 on 2017/4/13.
//  Copyright © 2017年 Kevin. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    //遍历构造函数
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认是16号字体
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否是返回按钮,如果是返回箭头
    convenience init(title:String, fontSize:CGFloat = 16, target:AnyObject?, action:Selector, isBack: Bool = false){
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageName), for: .normal)
            btn.setImage(UIImage(named:imageName + "highlighted"), for: .highlighted)
            //重新调整大小
            btn.sizeToFit()

        }
        //btn.addTarget(self, action: #selector(showFriends), for: .touchUpInside)
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //self.init 实例化UIBarButtonItem
        self.init(customView:btn)
    }
}
